package poker;
import javax.swing.*;
import java.awt.*;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class SpelerTafelGUI extends JPanel
{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public HoofdSchermGUI hgui;
	public KaartGUI kaart;
	private JPanel info = new JPanel();
	Speler speler;
	Deelname deelname;
	
	private Color backGround = new Color(0, 128, 0);		// groen zoals poker tafel
	
	private JLabel naamL = new JLabel();
	
	private String naam = "Speler";
	private double saldo = 100.0;
	private Deelname d;
	
	private boolean dealer = false;
	
	public SpelerTafelGUI(HoofdSchermGUI hh, Deelname d)
	{
		this.hgui = hh;
		this.d = d;
		
		setBackground( backGround );
		info.setBackground( backGround );
		
		//---------------------------------------
		// ik moet opschieten
		// dus ff snel wat paneltjes maken voor
		// kaarten en spelernaam/saldo
		//---------------------------------------
		
		setLayout( new BoxLayout(this, BoxLayout.Y_AXIS) );
		
		naamL.setText("<html>" + naam + "</html>");
		info.add(naamL);
		
		this.deelname = d;
		this.speler = d.getSpeler();
		naamL.setText("<html>" + speler.getNaam() + "<br><font color=\"red\">" + speler.getSaldo() + "</font><br />" + d.speler.spelerId + "</html>");
		
		kaart =  new KaartGUI( deelname.kaart.get(0), deelname.kaart.get(1), hh);
		
		if(this.speler == hh.speler)
		{
			kaart.showKaarten = true;
			kaart.drawDealerButton = hh.client.deelname.isDealer;
		}
		add(kaart);
		add(info);
		
	}
	
	public void setFold()
	{
		this.kaart.showKaarten = false;
		this.kaart.i = null;
		this.kaart.validate();
		this.kaart.repaint();
		validate();
		repaint();
	}
	
	public void setSaldo(double s)
	{
		
		saldo = s;
		naamL.setText("<html>" + hgui.client.spel.sr.zoekDeelname(hgui.client.deelname.speler.spelerId).speler.getNaam() + "<br><font color=\"red\">" + s + "<br></font></html>");
		validate();
		repaint();
	}
	
	public void setLastAction()
	{
		String nm = naamL.getText();
		int aantal = nm.length();
		String m = nm.substring(0, aantal - 7);
		m = m + "<br><font color=\"yellow\">" + hgui.client.spel.sr.lastAction + "</font></html>";
		//JOptionPane.showMessageDialog(null, m);
		//naamL.setText("<html>" + speler.getNaam() + "<br><font color=\"red\">" + saldo + "<br></font><font color=\"yellow\">" + hgui.client.spel.sr.lastAction + "</font><br />" + d.speler.spelerId + "</html>");
		naamL.setText(m);
		validate();
		repaint();
	}
	
	public void setGegevens(String naam, double saldo)
	{
		naamL.setText("<html>" + naam + "<br><font color=\"red\">" + saldo + "<br></font></html>");
		validate();
		repaint();
	}
	
	public void setDealer(boolean b)
	{
		dealer = b;
		kaart.drawDealerButton = b;
		kaart.repaint();
	}
		
}